//
//  PKRightViewController.m
//  PianKe
//
//  Created by lanou on 15/9/25.
//  Copyright (c) 2015年 lanou. All rights reserved.
//

#import "PKRightViewController.h"
#import "PKBaseViewController.h"
@interface PKRightViewController ()
@property(nonatomic,strong)NSArray *classArray;
@property(nonatomic,strong) PKBaseViewController *baseVC;
@property(nonatomic,strong)UINavigationController *navi;
@end

@implementation PKRightViewController
-(NSArray *)classArray
{
    if (_classArray==nil) {
        _classArray=@[@"PKGroupMainViewController",@"PKProductMainViewController",@"PKRadioMainViewController",@"PKReadViewController"];
    }
    return _classArray;
}
-(void)dealloc
{
    NSLog(@"hnehlhtr");

}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
//    self.view.backgroundColor=[UIColor yellowColor];
//    UIButton *button =[UIButton buttonWithType:UIButtonTypeSystem];
//    button.frame=CGRectMake(5, 70, 100, 100);
//    button.backgroundColor=[UIColor redColor];
//    
//    [button addTarget:self action:@selector(changeFrame) forControlEvents:UIControlEventTouchUpInside];
//    [self.view addSubview:button];
    [_navi.view removeFromSuperview];
    NSString *controllerName =self.classArray[0];
    self.baseVC=[[NSClassFromString(controllerName) alloc]init];
    _navi=[[UINavigationController alloc]initWithRootViewController:self.baseVC];
    _navi.navigationBar.hidden=YES;
    self.baseVC.changeFrameVC=self;
//    [self changeFrame];
    [self.view addSubview:self.navi.view];

}
-(void)changeFrame
{
    CGRect newFrame =self.view.frame;
    if (newFrame.origin.x==0) {
        newFrame.origin.x =SCREEN_WIDTH-40;
    }
    else
    {
        newFrame.origin.x=0;
    }
    [UIView animateWithDuration:1 animations:^{
        self.view.frame=newFrame;
    }];
    
    self.view.frame=newFrame;
}

-(void)changeViewWithIndex:(NSInteger )index
{
//    switch (index) {
//        case 0:
//            //创建电台控制器
//            //把电台控制的View添加到自己的视图上面
//            break;
//        case 1:
//            //1创建阅读控制器
//            //2把阅读控制的View添加到自己的视图上面
//            break;
//        case 2:
//            //1创建社区控制器
//            //2把社区控制的View添加到自己的视图上面
//            break;
//        case 3:
//            //1创建良品
//            //2把良品控制的View添加到自己的视图上面
//            break;
//        default:
//            break;
//    }
    //用NSClassFromString函数通过字符串获取某个类，然后动态的创建不同控制器，同时使用多态的思想，让父类指针接收子类对象
    NSString *controllerName =self.classArray[index];
   self.baseVC=[[NSClassFromString(controllerName) alloc]init];
    //创建一个导航控制器，让它去管理将要显示的界面，这样将要显示的界面才有push 的功能，因为导航控制器需要一直存在，所以需要定义为一个属性
    self.navi=[[UINavigationController  alloc]initWithRootViewController:self.baseVC];
    self.baseVC.changeFrameVC=self;
    _navi.navigationBar.hidden=YES;
    [self changeFrame];
    [self.view addSubview:self.navi.view];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
